import utils from '@js/utils.js' /* 共用的方法 */
export default {
    namespaced: true,
    state:{
        getDataList:{}, //数据列表
        //静态心电传参
        getParams:{
            "year":"",      //年
            "month":"",      //月
            "quarter":"",      //季度
            "dateType":"",        //0:近7天  1：本月 2：本季度 3:本年
            "orderBy":"",        //排序 检测时间:measure_time 心率:heart_rate RR:heart_rr PR:heart_pr QT:heart_qt QTC:heart_qtc
            "orderByType":"",    //排序类型 升序:asc 降序:desc
            "pNo":0,            //页数
            "pSize":10,          //显示条数

            //图表参数
            "tabState":"01",
            "showNumber":30,

        }
    },
    getters: {
        getDataList:(state) => {
            return state.getDataList
        },
        getParams:(state) => {
            return state.getParams
        },
    },
    mutations: {
        setDataList:(state, payload)=>{
            if(Object.keys(payload).length){
                var list=state.getDataList.lists ? state.getDataList.lists : [];
                state.getDataList = payload;
                state.getDataList.lists = list.concat(payload.lists)
            }else{
                state.getDataList = payload;
            }
        },
        setDataEcharts:(state, payload)=>{
            if(Object.keys(payload).length){
                var newList=[{"xAxis":[],"data":[]}];
                payload.lists.forEach((value, index, arr)=>{
                    newList[0].xAxis.push(value.measureTime+":"+state.getParams.pNo)
                    newList[0].data.push({"analysisId" : value.id,"value" : value.heartRate})
                })
                var xAxis=state.getDataList.lists ? state.getDataList.lists[0].xAxis : [];
                var data=state.getDataList.lists ? state.getDataList.lists[0].data : [];
                newList[0].xAxis=xAxis.concat(newList[0].xAxis);
                newList[0].data=data.concat(newList[0].data);
                payload.lists=newList;
                state.getDataList= payload;
            }else{
                state.getDataList = payload;
            }
        },
        setParams:(state, payload)=>{

            utils.extend(state.getParams, payload)
        },
    },
    actions: {

    }
}
